package com.jthinker.dao.impl;

import com.jthinker.dao.BaseDao;
import com.jthinker.dao.PostDao;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Map;

/**
 * User: Gang Chen
 * Date: 2015/5/13 21:48
 */
@Repository
public class PostDaoImpl implements PostDao
{
    @Resource
    private BaseDao baseDao;

    @Override
    public Map<String, Object> read(Serializable id)
    {
        return baseDao
                .read("SELECT p.id,p.title,p.content,p.excerpt, p.post_modified,p.comment_status,p.category_id FROM blog_post p LEFT JOIN blog_category c ON p.category_id=c.id WHERE p.id=?",
                        id);
    }

    @Override
    public void create(Map<String, Object> post) throws Exception
    {
        baseDao.insert("blog_post", post);
    }
}
